
var fs= require('fs')
var path = require('path')

const LOGFILE = './log/mylog.log' // 日志输出文件

/**
* @description 日志写入函数
* @param  writeStream  写入文件的流容器
* @param  log  写入文件的信息
*/
function writeLog(writeStream, log){
	writeStream.write(log + '\n')
}

/**
* @description 定义生成writeStream
*/
function createWriteStream(fileName){
	const fileFullName = path.resolve(__dirname, fileName)
	const writeStream = fs.createWriteStream(fileFullName, {
		flags: 'a'  //指定写入是追加的方式
	})
	return writeStream
}

/**
* @description 定义日志写入函数
* 
*/
function doLog(log){
    // 生成日志记录流实例
   const accessWriteStream = createWriteStream(LOGFILE)
   writeLog(accessWriteStream, log)
}
module.exports = {
    doLog
}